home *** CD-ROM | disk | FTP | other *** search
- Path: news.axess.com!news
- From: tdrymona@axess.com (Kamikaze)
- Newsgroups: comp.lang.c++
- Subject: Re: Pointer to non-static function
- Date: Sun, 10 Mar 1996 17:20:23 GMT
- Organization: Axess Communications, Montreal, Canada
- Message-ID: <4huok9$t8s@news.axess.com>
- References: <4hnsfs$cp2@nntp.ucs.ubc.ca>
- Reply-To: tdrymona@axess.com
- NNTP-Posting-Host: cretien.axess.com
- X-Newsreader: Forte Free Agent v0.55
-
- jamesdf@unixg.ubc.ca (James Fairweather) wrote:
-
- >I am attempting to make some code I've written more elegant by using a
- >pointer to a function. Here's how I declare the pointer:
-
- > double (*f)(double);
-
- >Now I'd like to make f point to one of two functions, one declared as:
-
- > double CFunction::Calculate(double);
-
- >and the other as:
-
- > double CEquation::Calculate(double);
-
- >Neither are static, and CEquation and CFunction are not related by
- >inheritance. Nor can they be, since CEquation contains a list of
- >CFunctions.
-
- >At compile time, the compiler issues an error, "cannot convert from
- >double (CFunction::*)(double) to double (__cdecl *)(double)" and
- >"cannot convert from double (CEquation::*)(double) to double (__cdecl
- >*)(double)".
-
- >This looks suspiciously like a typecasting problem to me. I'm
- >wondering if what I'm attempting to do is possible, and if so, how to
- >do it. What is the correct way to do the typecast, if that is the
- >problem? Any help is much appreciated.
-
- > James
-
- The compiler inserts a this pointer as the first argument of every
- method in a class. You have to manually put in the this pointer into
- the method declaration.
-
- So try
- double (*f)(CFunction*, double);
-
-
-
-
-